/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package builder;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author thinhnv
 */
public class JadBuilder {

    public static String midlet1 = "MIDlet-1: FunGame,/img/icon.png,main.Main";
    public static String midleJarSize = "MIDlet-Jar-Size: ";
    public static String midlerJarUrl = "MIDlet-Jar-URL: ";
    public static String midletName = "MIDlet-Name: FunGameR";
    public static String midletVendor = "MIDlet-Vendor: Vendor";
    public static String midletVersions = "MIDlet-Version: 1.0";
    public static String midletConfig = "MicroEdition-Configuration: CLDC-1.1";
    public static String midletProfile = "MicroEdition-Profile: MIDP-2.0";
    public String folderPath = "E:/BGATE/DATATOOLCBR/";
    private String newFileName;
    private String desPath = "";

    public void setDesPath(String desPath) {
        this.desPath = desPath;
    }

    public void setFolderPath(String folderPath) {
        this.folderPath = folderPath + File.separator;
    }

    public void setNewFileName(String newFileName) {
        this.newFileName = newFileName;
    }

    public static void setMidleJarSize(String midleJarSize) {
        JadBuilder.midleJarSize = midleJarSize;
    }

    public void creatDatFile() {
        PrintWriter pw = null;
        try {
            File jarFile = null;
            File datFile = null;
            if (desPath.length() == 0) {
                datFile = new File(folderPath + newFileName + ".jad");
                if (datFile.exists()) {
                    datFile.delete();
                }
                jarFile = new File(folderPath + newFileName + ".jar");
            } else {
                datFile = new File(desPath + newFileName + ".jad");
                if (datFile.exists()) {
                    datFile.delete();
                }
                jarFile = new File(desPath + newFileName + ".jar");
            }
            String jarSize = jarFile.length() + "";
            pw = new PrintWriter(new BufferedWriter(new FileWriter(datFile)));
            pw.println(midlet1);
            pw.println(midleJarSize + jarSize);
            pw.println(midlerJarUrl + newFileName + ".jar");
            pw.println(midletName);
            pw.println(midletVendor);
            pw.println(midletVersions);
            pw.println(midletConfig);
            pw.println(midletProfile);
            pw.flush();
            pw.close();
        } catch (IOException ex) {
            Logger.getLogger(JadBuilder.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            pw.close();
        }
    }
}
